package spring;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
//前置增强，before方法将会运行在业务方法之前
public class MyAdvice implements MethodBeforeAdvice, AfterReturningAdvice, MethodInterceptor {

    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        System.out.println("-----my before advice-------");
    }

    @Override
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("--------my after advice-------");
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("------around advice begin------");
        //让业务对象执行业务方法
        Object object=invocation.proceed();
        System.out.println("-----around advice end------");
        return object;
    }
}
